require 'test/unit'

require 'engine/action'
require 'models/character'
require 'models/item'

class CharacterDatabase
    def add(c)
        @instances.add(c)
    end
end
class SubAction < Action
end
class ActionTest < Test::Unit::TestCase
    def setup
        @char = Character.new
        @char.oid = 1
        CharacterDatabase.instance.add(@char)
    end
    def test_simple_action
        a = Action.new(:action,@char,{:key => :value})
        assert_equal(@char,a.performer)
        assert_equal(@char,a.owner)
    end
    def test_action_holds_only_valid_entities
        i = Item.new
        
        # missing oid
        assert_raises(RuntimeError) { Action.new(:action,i) }

        # has an oid
        i.oid = 1
        assert_nothing_raised { Action.new(:action, i) }

        a = Action.new(:action,i)
        # not in the database
        assert_nil(a.performer)
        assert_nil(a.owner)
    end
    def test_simple_sub_action
        a = SubAction.new(:action,@char,{:key => :value})
        assert_equal(@char,a.performer)
        assert_equal(@char,a.owner)
    end
end
